package com.g8.pethospitallearnbackend.mapper;

import com.g8.pethospitallearnbackend.entity.Exam;
import com.g8.pethospitallearnbackend.entity.ExamExample;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface ExamMapper {
    @SelectProvider(type=ExamSqlProvider.class, method="countByExample")
    long countByExample(ExamExample example);

    @DeleteProvider(type=ExamSqlProvider.class, method="deleteByExample")
    int deleteByExample(ExamExample example);

    @Delete({
        "delete from exam",
        "where exam_id = #{examId,jdbcType=VARCHAR}"
    })
    int deleteByPrimaryKey(String examId);

    @Insert({
        "insert into exam (exam_id, paper_id, ",
        "exam_name, exam_time, ",
        "exam_ddl)",
        "values (#{examId,jdbcType=VARCHAR}, #{paperId,jdbcType=VARCHAR}, ",
        "#{examName,jdbcType=VARCHAR}, #{examTime,jdbcType=INTEGER}, ",
        "#{examDdl,jdbcType=TIMESTAMP})"
    })
    int insert(Exam record);

    @InsertProvider(type=ExamSqlProvider.class, method="insertSelective")
    int insertSelective(Exam record);

    @SelectProvider(type=ExamSqlProvider.class, method="selectByExample")
    @Results({
        @Result(column="exam_id", property="examId", jdbcType=JdbcType.VARCHAR, id=true),
        @Result(column="paper_id", property="paperId", jdbcType=JdbcType.VARCHAR),
        @Result(column="exam_name", property="examName", jdbcType=JdbcType.VARCHAR),
        @Result(column="exam_time", property="examTime", jdbcType=JdbcType.INTEGER),
        @Result(column="exam_ddl", property="examDdl", jdbcType=JdbcType.TIMESTAMP)
    })
    List<Exam> selectByExample(ExamExample example);

    @Select({
        "select",
        "exam_id, paper_id, exam_name, exam_time, exam_ddl",
        "from exam",
        "where exam_id = #{examId,jdbcType=VARCHAR}"
    })
    @Results({
        @Result(column="exam_id", property="examId", jdbcType=JdbcType.VARCHAR, id=true),
        @Result(column="paper_id", property="paperId", jdbcType=JdbcType.VARCHAR),
        @Result(column="exam_name", property="examName", jdbcType=JdbcType.VARCHAR),
        @Result(column="exam_time", property="examTime", jdbcType=JdbcType.INTEGER),
        @Result(column="exam_ddl", property="examDdl", jdbcType=JdbcType.TIMESTAMP)
    })
    Exam selectByPrimaryKey(String examId);

    @UpdateProvider(type=ExamSqlProvider.class, method="updateByExampleSelective")
    int updateByExampleSelective(@Param("record") Exam record, @Param("example") ExamExample example);

    @UpdateProvider(type=ExamSqlProvider.class, method="updateByExample")
    int updateByExample(@Param("record") Exam record, @Param("example") ExamExample example);

    @UpdateProvider(type=ExamSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(Exam record);

    @Update({
        "update exam",
        "set paper_id = #{paperId,jdbcType=VARCHAR},",
          "exam_name = #{examName,jdbcType=VARCHAR},",
          "exam_time = #{examTime,jdbcType=INTEGER},",
          "exam_ddl = #{examDdl,jdbcType=TIMESTAMP}",
        "where exam_id = #{examId,jdbcType=VARCHAR}"
    })
    int updateByPrimaryKey(Exam record);
}